
// 模块
module.exports = {  
  req: req,

  // zhike支付检查
  getItemInfo:function getItemInfo(params){
    return req('getItemInfo',params)
  },
  getOneOrderInfo:function getOneOrderInfo(params){
    return req('getOneOrderInfo',params)
  },
  getOrderInfo:function getOrderInfo(params){
    return req('getOrderInfo',params)
  },
  getOrderInfoToShow:function getOrderInfoToShow(params){
    return req('getOrderInfoToShow',params)
  },
  getWxUserInfo:function getWxUserInfo(params){
    return req('getWxUserInfo',params)
  },
  getWxPhone:function getWxPhone(params){
    return req('getWxPhone',params)
  },
  wxPay:function wxPay(params){
    return req('wxPay',params)
  },
  wxAgainPay:function wxAgainPay(params){
    return req('wxAgainPay',params)
  },
  wxRefund:function wxRefund(params){
    return req('wxRefund',params)
  },
  // 人脸
  detectLiveFace:function detectLiveFace(params){
    return req('detectLiveFace',params)
  },
  createPerson:function createPerson(params){
    return req('createPerson',params)
  },
  getPerson:function getPerson(params){
    return req('getPerson',params)
  }

 }

// 以下为核心变量与方法，请勿随意改动
// 服务地址+普通request封装
const API_URL = 'http://yx.puhuatech.cn/';
// const API_URL = 'http://localhost:9002/';
const version = 'v1'
var req = function req(url,data) {
  var _url = API_URL + version + '/' + url ;
  return new Promise(function(resolve,reject){
    wx.request({
      url: _url,
      method:'POST',
      data:data,
      dataType:'json',
      success:function success(res) {
        resolve(res.data)
      },
      fail: function fail(error) {
        reject(error);
      },
      complete: function complete(aaa) {
        // 加载完成
      }
    })
  })
};

// 定义小程序的promise的finally方法
Promise.prototype.finally = function (callback) {
  var Promise = this.constructor;
  return this.then(function (value) {
    Promise.resolve(callback()).then(function () {
      return value;
    });
  }, function (reason) {
    Promise.resolve(callback()).then(function () {
      throw reason;
    });
  });
};
